 <?php
/**
 * Content - Simple Product Snapshot
 *
 * @version 1.5.0
 * @package Joomla
 * @subpackage plugins
 * 
 * @author Bruno Pourtier
 * @website http://forge.joomla.org/gf/project/simplesnapshot/
 * @email bruno.pourtier@gmail.com
 * @copyright (C) 2008-2011 Bruno Pourtier
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
 *
 * http://www.joomla.org
 *
 * VirtueMart is Free Software.
 * VirtueMart comes with absolute no warranty.
 * http://virtuemart.net
 *
 * Seber Cart is Free Software.
 * Seber Cart comes with absolute no warranty.
 * http://sebercart.com/
 */
defined( '_JEXEC' ) or die( 'Restricted access' );

// Import library dependencies
jimport( 'joomla.plugin.plugin' );
jimport( 'joomla.methods' );

class plgContentSimpleProductSnapshot extends JPlugin
{
	/**
	 * MAIN CONFIGURATION
	 * pluginPath:		Complete path to the simpleproductsnapshot folder
	 * pluginUrl:		Complete url to the simpleproductsnapshot folder
	 * pluginParams:	Product & main parameters, use class JParameter
	 */
	var $_regex = '/{simpleproduct:.+?}/';
	var $_name = 'simpleproduct';
	var $_pluginPath;
	var $_pluginUrl;
	var $_pluginParams;
	
	//Constructor
	function plgContentSimpleProductSnapshot( &$subject, $params )
	{
		parent::__construct( $subject );
		
		// load plugin parameters
		$this->plugin = JPluginHelper::getPlugin( 'content', 'simpleproductsnapshot' );
		$this->_pluginParams = new JParameter( $this->plugin->params );
		$this->_pluginPath = JPATH_PLUGINS . DS . 'content' . DS . 'simpleproductsnapshot' . DS;
		$this->_pluginUrl = JURI::root() . 'plugins/content/simpleproductsnapshot/';
	}
	
	function onPrepareContent( &$row, &$params, $limitstart = null )
	{
		global $mainframe;
		
		/**
		 * FILES INSERTION
		 */
		 // Load language translation
		JPlugin::loadLanguage('plg_content_simpleproductsnapshot', JPATH_ADMINISTRATOR);
		
		/**
		 * INTEGRATION WITH DIFFERENT ECOMMERCE SYSTEM
		 */
		switch ($this->_pluginParams->get('ecommerce'))
		{
			default:
			case 'virtuemart':
        require_once($this->_pluginPath . 'classes' . DS . 'virtuemart.class.php');
				$currentCart = new VirtueMartProductSnapshot();
				break;
			case 'sebercart':
        require_once($this->_pluginPath . 'classes' . DS . 'sebercart.class.php');
				$currentCart = new SeberCartProductSnapshot();
				break;
		}
		
		$currentCart->_pluginPath = $this->_pluginPath;
    $currentCart->_pluginUrl = $this->_pluginUrl;
    $currentCart->_pluginParams = $this->_pluginParams;
    $currentCart->_name = $this->_name;   //Comment this line if you want to use the {vmproduct}, or {sbproduct} regex
    $currentCart->_regex = $this->_regex; //Comment this line if you want to use the {vmproduct}, or {sbproduct} regex
    $currentCart->_text = $row->text;
    $currentCart->onPrepareContent();
    $row->text = $currentCart->_text;
	}
}
?>